﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core.Models;

namespace Core.Controllers
{
    public class SitemapController : Controller
    {
        //
        // GET: /Sitemap/

        public ActionResult Index()
        {
            CoreEntities core = new CoreEntities();
            Guid BUId = (Guid)Session["BusinessUnitId"];
            Guid DomainId = (Guid)Session["DomainId"];
            List<string> urls = new List<string>();
            List<Page> list = core.Pages.Where(m => (m.IsDroppedYN == "N" && m.BusinessUnitId == BUId)).OrderBy(m => m.CreateDT).ToList();
            if (list.Count > 0)
            {
                foreach (Page page in list)
                {
                    if (UserPermissions.HasPermission(page.Permission.Name))
                    {
                        string url = (Request.IsSecureConnection ? "https://" : "http://") +  Session["DomainName"] + page.PageName.Substring(1);
                        urls.Add(url);
                    }
                }
            }
            ViewBag.Urls = urls;
            return View();
        }

    }
}
